from sanic import response
from router.router import *
from conf import *


@app.route('/test')
async def test(request):
        return response.text('http success!')


@app.middleware('response')#用于处理跨域的问题，只要是响应，都会经过此中间件，加上用于跨域的头
async def handle_reponse_wx(request,response):
    response.headers["Access-Control-Allow-Origin"] = '*'
    response.headers["Access-Control-Allow-Methods"] = "POST,GET,OPTIONS"
    response.headers["Access-Control-Expose-Headers"] = "Set-Cookie,token"
    response.headers["Access-Control-Allow-Headers"] = "Set-Cookie,token"
    response.headers["Access-Control-Allow-Credentials"] = "true"


if __name__=="__main__":
    # thread_loop1 = asyncio.new_event_loop()
    # t1 = threading.Thread(target=websocket_thread_loop_task, args=(thread_loop1,))
    # t1.setDaemon(True)
    # t1.start()
    #
    # thread_loop2 = asyncio.new_event_loop()
    # t2 = threading.Thread(target=produce_websocket_loop, args=(thread_loop2,))
    # t2.setDaemon(True)
    # t2.start()

    app.run(host=WEB_HOSTNAME,
            port=WEB_PORT,
            workers=1,
            auto_reload=False,
            debug=False)
